package com.tengniu.api.common;

import com.tengniu.biz.bo.LoginResultBO;
import com.tengniu.common.exception.ServiceException;

public class CurrentUser {

    public static volatile ThreadLocal<LoginResultBO> REDIS_USER = new ThreadLocal<>();

    /**
     * 获取当前token登录的用户
     * @return
     */
    public static LoginResultBO getCurrentUser(){
        return REDIS_USER.get();
    }

    public static Long getUserId() {
        LoginResultBO loginResultBO = REDIS_USER.get();
        if (loginResultBO == null) {
            throw new ServiceException("用户未登录");
        }
        return loginResultBO.getId();
    }
}
